package com.java.test.interview.minshengyidai;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.ArrayList;
import java.util.List;

/**
 * @author TonyOne
 * @version 1.0
 * @desc
 * @date 2018/10/16 9:48
 * @company
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class User implements Comparable<User>{

    private Integer userId;
    private String userName;
    private String address;
    private Double score;

    public int User() {
        return 1;
    }

    public static void main(String[] args) {
        List<User> list = new ArrayList<>();
        User user1 = new User(1,"mike","XDD",80.00);
        User user2 = new User(1,"Anna","ZUV",100.00);
        User user3 = new User(1,"liux","LRA",59.00);
        list.add(user1);
        list.add(user2);
        list.add(user3);

//        for(User u : list) {
//            if(u.getUserName().indexOf("x")>-1)
//                list.remove(u);//Exception in thread "main" java.util.ConcurrentModificationException
//        }

//        Collections.sort(list);
//        System.out.println(list);
//        for(int i=0,size=list.size();i<size;i++) {
//            if(list.get(i).getUserName().indexOf("x")>-1)
//                // 按下标遍历可以成功删除
//                list.remove(i);
//        }
//        System.out.println(list);

        // 删除要用迭代器
//        Iterator<User> iterator = list.iterator();
//        while (iterator.hasNext()) {
//            User u = iterator.next();
//            if(u.getUserName().indexOf("x")>-1)
//                iterator.remove();
//        }
//        System.out.println(list);

//        list.removeIf(u->u.getUserName().indexOf("x")>-1);
//        System.out.println(list);
//        list.sort(Comparator.comparing(User::getUserName));
        list.sort((u1,u2)->u1.getUserName().toLowerCase().compareTo(u2.getUserName().toLowerCase()));
//        System.out.println(list);
        System.out.println(new User().User());
    }

    @Override
    public int compareTo(User u) {
        return userName.toLowerCase().compareTo(u.getUserName().toLowerCase());
    }
}
